package com.cysion.study.ui.fragment

import android.os.Bundle
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import com.cysion.other.color
import com.cysion.study.R
import com.cysion.study.ktbox.base.BaseFragment
import com.cysion.study.ktbox.base.BaseFragmentAdapter
import com.cysion.study.ktbox.utils.darkTextTheme
import com.cysion.study.uibox.bar.TopBar
import kotlinx.android.synthetic.main.fragment_p_order.*
import java.util.*

/**
 * 家教新首页
 * Created by chu on 2019-06-30.
 */
class POrderFragment : BaseFragment() {
    override fun getLayoutId(): Int {
        return R.layout.fragment_p_order
    }

    private lateinit var mFragments: MutableList<Fragment>
    private lateinit var mTitles: MutableList<String>

    override fun initView() {
        activity!!.darkTextTheme(activity!!.color(R.color.white))
        topbar.apply {
            setTitleBackColor(color(R.color.white))
            initElements(TopBar.ELEMENT.HIDE, TopBar.ELEMENT.TEXT, TopBar.ELEMENT.HIDE)
            setTitle("订单管理")
            setTitleColor(color(R.color.black))

        }

        vp_content.offscreenPageLimit = 4
        vp_content.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(main_tablayout))

        mFragments = getFragments()
        mTitles = getTitles()
        vp_content.adapter =
            BaseFragmentAdapter(childFragmentManager, mFragments, mTitles)
        main_tablayout.setupWithViewPager(vp_content)
//        tablayout.tabTextColors = resources.getColorStateList(R.color.main_cl)
        main_tablayout.setSelectedTabIndicatorColor(resources.getColor(R.color.main_cl))

        main_tablayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
            override fun onTabReselected(tab: TabLayout.Tab?) {


            }

            override fun onTabUnselected(tab: TabLayout.Tab?) {
            }

            override fun onTabSelected(tab: TabLayout.Tab?) {
            }

        })

    }


    private fun getTitles(): MutableList<String> {
        val strings = ArrayList<String>()
        strings.add("全部")
        strings.add("待确认")
        strings.add("待付款")
        strings.add("退款")
        return strings
    }

    private fun getFragments(): MutableList<Fragment> {
        val fragmentArrayList = ArrayList<Fragment>()
        val f1 = POrderChildFragment()
        val f2 = POrderChildFragment()
        val f3 = POrderChildFragment()
        val f4 = POrderChildFragment()
        val b1 = Bundle()
        val b2 = Bundle()
        val b3 = Bundle()
        val b4 = Bundle()
        //不填代表全部；14代表待确认；0代表待付款；100代表退款
        b1.putString("type", "")
        f1.arguments = b1

        b2.putString("type", "14")
        f2.arguments = b2

        b3.putString("type", "0")
        f3.arguments = b3

        b4.putString("type", "100")
        f4.arguments = b4

        fragmentArrayList.add(f1)//未签到
        fragmentArrayList.add(f2)//已签到
        fragmentArrayList.add(f3)//已签到
        fragmentArrayList.add(f4)//已签到
//        fragmentArrayList.add(NoSignInFragment())//已签到
        return fragmentArrayList
    }

    override fun closeMvp() {
    }
}